<?php
/********************************************\
 * 框架核心文件：Run.php
 * 功能：为框架提供路由功能
 * 需要在入口文件中加入
 +-------------------------------------------
 * www.cnblogs.com/SmilingLiuWei
 * SmilingLiuWei@163.com
\********************************************/

class Run {
	Public function __construct() {
		// 找到模块和方法
		if(empty($_SERVER['PATH_INFO'])){
			$this->redirect('indx.php');
		}
		else(){
			$this->url_arr = explode('/', trim($_SERVER['PATH_INFO'], '/'));
			$this->module_name = $this->url_arr[0].'_Controller';
			$this->method_name = $this->url_arr[1];
		}

		// 获得所有参数
		$times = count($this->url_arr);
		if($times%2 == 0){
			for($i=2; $i<$times; $i+=2){
				$_GET[$this->url_arr[$i]] = $this->url_arr[$i+1];
			}
		}

		// 创建对象
		if(class_exists($this->module_name)){
			$obj = new $this->module_name;
			if(method_exists($this->module_name, $this->method_name))
				$obj->{$this->method_name}();
			else{
				new Message(' 您访问的地址有误');
				exit;
			}
		}
		else{
			new Message(' 您访问的地址有误');
			exit;
		}
	}

	private $module_name;
	private $method_name;
	private $url_arr;
}
